<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 父组件模板 -->
    <div id="app">
        <cpn @itemClick="cpnclick"></cpn>
    </div>
    <!-- 子组件模板 -->
    <template id="cpn">
        <div>
            <button v-for="item in categories" @click="btnClick(item)">{{item.name}}</button>
        </div>

    </template>
    <script src="../vue.js"></script>
    <script>
        const cpn = {
            template: '#cpn',
            data() {
                return {
                    categories: [
                        {id: 'aaa', name: 'basketball'},
                        {id: 'bbb', name: 'football'},
                        {id: 'ccc', name: 'volleyball'},
                        {id: 'ddd', name: 'handball'}

                    ]
                }
            },
            methods: {
                btnClick(item) {
                    this.$emit('itemclick', item)
                }
            }
        }
        const app = new Vue({
            el: '#app',
            components: {
                cpn
            },
            methods: {
                cpnclick(item) {
                    console.log(item);
                }
            }
            
        })
    </script>
</body>
</html>